package com.example.hello;

import com.example.hello.client.ProgressBar.BootstrapProgressBarState;
import com.vaadin.server.Page;
import com.vaadin.ui.AbstractComponent;

public class BootstrapProgressBar extends AbstractComponent {

    public enum Color {
        DANGER, DEFAULT, INFO, SUCCESS, WARNING
    }

    public enum Style {
        ANIMATED, DEFAULT, STRIPED
    }

    public enum Device {
        DESKTOP, PHONE, TABLET
    }

    public BootstrapProgressBar() {
        this(Style.DEFAULT);
    }

    public BootstrapProgressBar(Style style) {
        setType(style);
        Page.Styles styles = Page.getCurrent().getStyles();
        if (!styles.toString().contains(".helloVG .no-margin")) {
            styles.add(".helloVG .no-margin { margin-bottom: 0; }");
        }
    }

    @Override
    protected BootstrapProgressBarState getState() {
        return (BootstrapProgressBarState) super.getState();
    }

    public boolean isActive() {
        return getState().isActive();
    }

    public void setActive(boolean active) {
        getState().setActive(active);
    }

    public Color getColor() {
        return Color.valueOf(getState().getColor());
    }

    public void setColor(Color color) {
        getState().setColor(color.toString());
    }

    public int getPercent() {
        return getState().getPercent();
    }

    public void setPercent(int percent) {
        getState().setPercent((percent > 100) ? 100 : ((percent < 0) ? 0 : percent));
    }

    public String getText() {
        return getState().getText();
    }

    public void setText(String text) {
        getState().setText(text);
    }

    public String getTitle() {
        return getState().getTitle();
    }

    public void setTitle(String title) {
        getState().setTitle(title);
    }

    public Style getType() {
        return Style.valueOf(getState().getType());
    }

    public void setType(Style style) {
        getState().setType(style.toString());
    }

}